//
//  MYVendingMachineListTavleCell.m
//  MiYuan_iOS
//
//  Created by zhangyongbing on 2018/5/8.
//  Copyright © 2018年 zhangyongbing. All rights reserved.
//

#import "MYVendingMachineListTavleCell.h"

@interface MYVendingMachineListTavleCell()
@property (nonatomic,weak) IBOutlet   UIImageView     *imgIcon;
@property (nonatomic,weak) IBOutlet   UILabel         *labTitle;
@property (nonatomic,weak) IBOutlet   UILabel         *labNumber;
@property (nonatomic,weak) IBOutlet   UILabel         *labtitme;
@property (nonatomic,weak) IBOutlet   WHSScycleView   *cleview;
@property (nonatomic,weak) IBOutlet   UILabel         *labpercent;

@end;

@implementation MYVendingMachineListTavleCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
//    MMProgressView *progress = [[MMProgressView alloc]initWithFrame:CGRectMake(100, 100, 42, 42)];
//    self.progress = 0.5;
//    [self addSubview:progress];
    CGColorRef color = [UIColor colorWSHHFromHexString:@"#F1F1F1"].CGColor;
    [self.imgIcon.layer setMasksToBounds:YES];
    [self.imgIcon.layer setCornerRadius:2]; //设置矩形四个圆角半径
    [self.imgIcon.layer setBorderWidth:1]; //边框宽度
    [self.imgIcon.layer setBorderColor:color];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setDataToViewWithDictionary:(NSDictionary *)dic
{
    [self.labTitle setText:[dic objectForKey:@"pointName"]];
    NSString *number = [NSString stringWithFormat:@"%@",[dic objectForKey:@"number"]];
    if ([number stringIsValid]) {
        [self.labNumber setText:number];
    }
    else{
        [self.labNumber setText:@""];
    }
    NSString *lastReplenishmentTime = [NSString stringWithFormat:@"%@",[dic objectForKey:@"lastReplenishmentTime"]];
    if ([lastReplenishmentTime stringIsValid]) {
        NSString *timetext = [NSString stringWithFormat:@"上次补货时间：%@",lastReplenishmentTime];
        [self.labtitme setText:timetext];
    }
    else{
        
        [self.labtitme setText:@"上次补货时间："];
    }
    NSString *imgurl =[NSString stringWithFormat:@"%@",[dic objectForKey:@"picture"]];
//    [self.imgIcon sd_setImageWithURL:[NSURL URLWithString:imgurl] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
//        
//    }];
    [self.imgIcon sd_setImageWithURL:[NSURL URLWithString:imgurl] placeholderImage:[UIImage imageNamed:@"defautMachine"]];
    
    NSString *salesRatioString  = [NSString stringWithFormat:@"%@",[dic objectForKey:@"salesRatioString"]];
    NSInteger intsalesRatio = [salesRatioString integerValue];
    CGFloat salesRatio= [salesRatioString floatValue];
    self.cleview.percent = salesRatio/100;
    NSString *strPercent = @"";
    if (salesRatio >= 100) {
        strPercent = @"已售";
    }
    else
    {
        strPercent = [NSString stringWithFormat:@"%ld%%",100-(long)intsalesRatio];
    }
    [self.labpercent setText:strPercent];
    
}

@end
